package com.efurniture.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.efurniture.blo.AdministratorBLO;

@Controller
public class AdministratorController {
	
	AdministratorBLO adminBLO;
	
	public void setAdminBLO(AdministratorBLO value){
		adminBLO = value;
	}
	
	@RequestMapping("administrator/login.htm")
	public @ResponseBody ModelAndView login(HttpServletRequest request, HttpServletResponse response){
		String user = request.getParameter("user");
		String pass = request.getParameter("pass");
		
		
		boolean check = this.adminBLO.checkAccount(user, pass);
		if(check){
			HttpSession session  = request.getSession(true);
			session.setAttribute("user", user);
			//return new ModelAndView("redirect: /welcome.htm");
			ModelAndView mav = new ModelAndView();
	        mav.setViewName("index");
	        mav.addObject("sampleContentList", "");
	        return mav;
		}
		return new ModelAndView("redirect: /welcome.htm");
		
		
	}
}
